<?php

namespace App\Console\Commands;

use App\Models\Article;
use App\Models\Circle;
use App\Models\User;
use App\Mongo\ArticleMon;
use App\Mongo\CircleMon;
use App\Services\UserWeightService;
use Illuminate\Console\Command;

class CircleMonCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'circle-mon';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        Circle::whereNotNull('longitude')->whereIn('status', [1,2])->where('is_activity', 0)->chunk(100, function ($list) {
            foreach ($list as $item) {
                CircleMon::create([
                    'id' => intval($item->id),
                    'city' => $item->city,
                    'status' => $item->status,
                    'is_activity' => $item->is_activity,
                    'location' => [
                        'type' => 'Point',
                        'coordinates' => [
                            floatval($item->longitude),
                            floatval($item->latitude)
                        ]
                    ],
                    'city_code' => $item->city_code
                ]);
            }
        });
    }
}
